import {defineConfig, loadEnv} from "vite";
import vue from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { LayuiVueResolver } from "unplugin-layui-vue-resolver";
import {viteCommonjs} from "@originjs/vite-plugin-commonjs";

// @ts-ignore
export default defineConfig((mode: string) => {
  const env = loadEnv(mode, process.cwd());
  return {
    plugins: [
      vue(),
      viteCommonjs(),
      AutoImport({
        resolvers: [
          LayuiVueResolver(),
        ],
      }),
      Components({
        resolvers: [
          LayuiVueResolver({
            resolveIcons: true,
          }),
        ],
      }),
    ],
    server: {
      https: false, // 是否开启 https
      open: false, // 是否自动在浏览器打开
      cors: true, // 允许跨域  8月更新
      port: env.VITE_BASE_PORT,
      host: "0.0.0.0",
      proxy: {
        '/aiApi': {      // 'http:// 10.188.119.162:8182'
          target: 'http://localhost:8182',
          changeOrigin: true,
          secure: false,
        //  rewrite: (path) => path.replace(/^\/aiApi\//, '/api/'),
        },
        "/api": {
          target: env.VITE_TARGET_URL, // apifox的mock接口
          changeOrigin: true,
          secure: false, // 如果是https接口，需要配置这个参数
          // ws: true, //websocket支持
          rewrite: (path) => path.replace(/^\/api/, ""),
        },
        "/hqApi": {
          target: 'http://127.0.0.1:8890', // apifox的mock接口
          changeOrigin: true,
          secure: false, // 如果是https接口，需要配置这个参数
          // ws: true, //websocket支持
          // rewrite: (path) => path.replace(/^\/hqapi/, "hqApi"),
        },
        "/fastApi": {
          target: 'http://127.0.0.1:8015', // apifox的mock接口
          changeOrigin: true,
          secure: false, // 如果是https接口，需要配置这个参数
          rewrite: (path) => path.replace(/^\/fastApi/, ""),
        },
        "/mockTool": {
          target: 'http://10.20.181.131:8082/mockTool', // apifox的mock接口
          changeOrigin: true,
          secure: false, // 如果是https接口，需要配置这个参数
          rewrite: (path) => path.replace(/^\/mockTool/, ""),
        }
      },
    },
  }

});